package com.example.ws.handler.chess;

import java.util.ArrayList;
import java.util.List;

public class BoxChessUtil {


    public void nextStep(int[][] chess, int x, int y, int chessType) {
    }

    // 深度遍历 极大值搜索
    public void maxSearch(int [][]chess, int chessType) {
        for (int i = 0; i < chess.length; i++) {
            for (int j = 0; j < chess[i].length; j++) {

            }
        }
    }

    // 构建搜索树
    public void constructSTree(BoxChess boxChess, int deep) {
        // 获得这个最近落点的附近 - 最近1个格所有落点位置
        Pos lastDownPos = boxChess.lastDownPos;
        int[][] chess = boxChess.chess;
        List<Pos> aroundPoses = aroundDownPoses(chess, lastDownPos, 1);
        SearchTree searchTree = new SearchTree();

    }

    public void doConstructSearchTree(int[][] chess, Pos lastDown, int deepLimit, int nowDeep, SearchTree root) {
        if (root == null || nowDeep >= deepLimit) return;
        List<Pos> aroundPoses = aroundDownPoses(chess, lastDown, 1);
        root.children = SearchTree.batchChildren(aroundPoses);
        for (int i = 0; i < aroundPoses.size(); i++) {

        }

    }

    // 获得这个最近落点的附近 - 最近1个格所有落点位置
    public List<Pos> aroundDownPoses(int[][] chess, Pos lastDown, int range) {
        List<Pos> aroundDownPoses = new ArrayList<>();
        for (int i = -1 * range; i < range; i++) {
            for (int j = -1 * range; j < range; j++) {
                // 这个点位不是自身并且无落点
                if (i != lastDown.x() && j != lastDown.y() && chess[i][j] == BoxChess.CHESS_TYPE_NONE) {
                    aroundDownPoses.add(new Pos(i, j));
                }
            }
        }
        return aroundDownPoses;
    }


}
